<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改销售记录')" />
</head>
<body>
<form class="layui-form" th:object="${hospitalSaleinfo}">
    <div class="mainBox">
        <div class="main-container">
            <input name="id" th:field="*{id}" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label">药品名称：</label>
        <div class="layui-input-block">
            <input type="text" name="dname" th:field="*{dname}" placeholder="请输入药品名称" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">药品编号：</label>
        <div class="layui-input-block">
            <input type="text" name="dnumber" th:field="*{dnumber}" placeholder="请输入药品编号" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数量：</label>
        <div class="layui-input-block">
            <input type="text" name="count" th:field="*{count}" placeholder="请输入数量" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">金额：</label>
        <div class="layui-input-block">
            <input type="text" name="total" th:field="*{total}" placeholder="请输入金额" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">操作人：</label>
        <div class="layui-input-block">
            <input type="text" name="operator" th:field="*{operator}" placeholder="请输入操作人" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">操作时间：</label>
        <div class="layui-input-block">
            <div class="input-group date">
                <input type="text" name="operatetime" class="layui-input" id="operatetime" >
            </div>
        </div>
    </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="saleinfo-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    layui.use(['form', 'jquery','laydate','dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        let prefix = "/hospital/saleinfo/";

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        laydate.render({
                            elem: '#operatetime'
                        });
                                                        
        form.on('submit(saleinfo-update)', function (data) {
            for(var key in data.field){
                var type=$(data.form).find("input[name='"+key+"']").attr("type");
                if(type=="checkbox"){
                    var value="";
                    $(data.form).find("input[name='"+key+"']:checked").each(function(){
                        value+=$(this).val()+",";
                    })
                    if(value!=""){
                        value=value.substr(0,value.length-1);
                        data.field[key]=value;
                    }

                }
            }
            $.ajax({
                url: prefix+'update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("saleinfo-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    });
</script>
</html>